/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-06-14 13:27:05
 */
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
import clueMgr from '@/biz/businessReport/clue'
import CustomerMgr from '@/biz/customer/customerOpt.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      title: '线索手机号',
      field: 'customerPhone',
      minWidth: 180,
      header: {
        filter: {
          title: '线索手机号',
          key: 'cluePhone',
          placeholder: '请输入至少4位线索手机号',
          input: {},
          check: (val) => {
            if (val.customerPhone.length < 4) {
              _this.$Message.warning('请输入至少4位线索手机号。')
            }
            return !(val.customerPhone.length < 4)
          }
        },
      }
    },
    {
      field: 'customerName',
      minWidth: 150,
      title: '客户姓名',
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    },
    {
      title: '线索来源渠道',
      field: 'clueChannelName',
      minWidth: 180,
      header: {
        filter: {
          title: '线索来源渠道',
          key: 'clueChannelIds',
          placeholder: '请选择线索来源渠道',
          load: (o) => {
            clueMgr.getListClueChannel({})
              .then((res) => {
                o.select.options = res
              })
              .catch((err) => {})
          },
          select: {
            options: [],
            multiple: true,
            filterable: true
          }
        },
      },
    },
    {
      title: '获取方式',
      field: 'clueChannelName',
      minWidth: 180,
      header: {
        filter: {
          title: '获取方式',
          key: 'clueChannelIds',
          placeholder: '请选择获取方式',
          load: (o) => {
            clueMgr.getListClueChannel({})
              .then((res) => {
                o.select.options = res
              })
              .catch((err) => {})
          },
          select: {
            options: [],
            multiple: true,
            filterable: true
          }
        },
      },
    },
    {
      title: '线索生成日期',
      field: 'createTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '线索生成日期',
          startKey: 'startTime',
          endKey: 'endTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.startTime, val
                .endTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('线索生成日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.startTime, val
              .endTime).Y >= 2)
          }
        }),
      },
    },
    {
      title: '是否首推',
      field: 'isFirstPush',
      minWidth: 150,
      header: {
        filter: {
          title: '是否首推',
          key: 'cooperationType',
          placeholder: '请选择是否首推',
          select: {
            options: []
          },
        },
      },
    },
    {
      title: '推送次数',
      field: 'isFirstPush',
      minWidth: 150,
    },
    {
      title: '推送状态',
      field: 'pushStatus',
      minWidth: 130,
    },
    {
      title: '推送结果说明',
      field: 'pushResult',
      minWidth: 180,
      header: {
        filter: {
          title: '推送结果说明',
          key: 'pushResultIds',
          placeholder: '请选择推送结果说明',
          load: (o) => {
            clueMgr.getListPushResult({})
              .then((res) => {
                o.select.options = res
              })
              .catch((err) => {})
          },
          select: {
            options: [],
            multiple: true,
            filterable: true
          }
        },
      },
    },
    {
      title: '推送事业部',
      field: 'pushDivision',
      minWidth: 150,
    },
    {
      title: '推送子公司',
      field: 'pushCompany',
      minWidth: 130,
    },
    {
      title: '推送事业处',
      field: 'pushOffice',
      minWidth: 180,
    },
    {
      title: '推送案场',
      field: 'pushBuilding',
      minWidth: 170,
    },
    {
      title: '推送顾问',
      field: 'pushUserName',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, nameOpt.createPeople({
            key: 'counselorId',
            title: '推送顾问',
            to: (info) => {
              return {
                pushUserNo: info.workNo,
                pushUserName: info.name
              }
            }
          }))
        },
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.pushUserName + '(' + params.row.pushUserNo + ')'
          })
        }
      }
    },
    {
      title: '是否转到访线索',
      field: 'visitDate',
      minWidth: 180,
      header: {
        filter: {
          title: '是否转到访线索',
          key: 'cooperationType',
          placeholder: '请选择是否转到访线索',
          select: {
            options: []
          },
        },
      },
    },
    {
      title: '转到访日期',
      field: 'visitDate',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '转到访日期',
          startKey: 'startTime',
          endKey: 'endTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.startTime, val
                .endTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('转到访日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.startTime, val
              .endTime).Y >= 2)
          }
        }),
      },
    },
    {
      title: '到访渠道',
      field: 'visitChannel',
      minWidth: 180,
      header: {
        filter: {
          title: '到访渠道',
          key: 'clueChannelIds',
          placeholder: '请选择到访渠道',
          load: (o) => {
            clueMgr.getListClueChannel({})
              .then((res) => {
                o.select.options = res
              })
              .catch((err) => {})
          },
          select: {
            options: [],
            multiple: true,
            filterable: true
          }
        },
      },
    },
    {
      title: '客户进度',
      field: 'customerStatus',
      minWidth: 130,
      header: {
        filter: {
          title: '客户进度',
          key: 'status',
          placeholder: '请选择客户进度',
          load: (o) => {
            o.select.options = CustomerMgr.status()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      },
    },
    {
      title: '线索有效性',
      field: 'customerStatus',
      minWidth: 130,
      header: {
        filter: {
          title: '线索有效性',
          key: 'cooperationType',
          placeholder: '请选择线索有效性',
          select: {
            multiple: true,
            options: []
          },
        },
      },
    },
    {
      title: '线索有效性说明',
      field: 'customerStatus',
      minWidth: 130,
    },
    {
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: _this.unlocking('0104020200') ? '查看详情' : '',
            event: 'detailFun',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }]
  }

}

export default Column